home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacsBug / MacsBug 6.1 / dcmds / Pascal Samples / Echo.p < prev    next >
Encoding:
Text File  |  1989-04-21  |  2.2 KB  |  91 lines  |  [TEXT/MPS ]

  1. UNIT Echo;
  2.  
  3. (* The following MPW commands will build the dcmd and copy it to the
  4.    "Debugger Prefs" file in the System folder. The dcmd's name in
  5.          MacsBug will be the name of the file built by the Linker.
  6.  
  7.         Pascal Echo.p
  8.         Link dcmdGlue.a.o Echo.p.o {Libraries}Runtime.o {PLibraries}PasLib.o -o Echo
  9.         BuildDcmd Echo 101
  10. *)
  11.  
  12. {$R-}
  13.  
  14. INTERFACE
  15.  
  16.         USES MemTypes, dcmd;
  17.         
  18.   { Public declaration for dcmdGlue. Must be in every dcmd. The name cannot be changed. }
  19.         PROCEDURE CommandEntry (paramPtr: dcmdBlockPtr);
  20.  
  21.  
  22. IMPLEMENTATION
  23.  
  24. CONST CR = $0D;
  25.  
  26.  
  27. PROCEDURE NumberToHex (number: LONGINT; VAR hex: Str255);
  28. VAR digits: Str255;
  29.     n: INTEGER;
  30. BEGIN
  31.   digits := '0123456789ABCDEF';
  32.         hex    := '00000000';
  33.         FOR n := 8 DOWNTO 1 DO
  34.           BEGIN
  35.                 hex[n] := digits[1 + (number MOD 16)];
  36.                 number := number DIV 16;
  37.                 END;
  38. END;
  39.  
  40.  
  41. PROCEDURE CommandEntry (paramPtr: DCmdBlockPtr);
  42. VAR pos:   INTEGER;
  43.     ch:    CHAR;
  44.                 value: LONGINT;
  45.                 ok:    BOOLEAN;
  46.                 str:   Str255;
  47. BEGIN
  48.   IF paramPtr^.request = dcmdInit THEN
  49.           BEGIN { The dcmd gets called once when loaded to init itself }
  50.                 END
  51.         ELSE
  52.   IF paramPtr^.request = dcmdDoIt THEN
  53.           BEGIN { Do the command's normal function }
  54.                 dcmdDrawLine ('Echoing parameters');
  55.  
  56.     REPEAT
  57.       { Save the position so we can rewind if we get an error }
  58.                   pos := dcmdGetPosition;
  59.                         ch  := dcmdPeekAtNextChar;
  60.                         IF ch IN ['A'..'Z', 'a'..'z'] THEN
  61.                                 BEGIN { Get the parameter as a text string }
  62.                                 ch := dcmdGetNextParameter (str);
  63.                                 dcmdDrawLine (str);
  64.                                 END
  65.                         ELSE
  66.                                 BEGIN { Get the parameter as a 32 bit value }
  67.                                 ch := dcmdGetNextExpression (value, ok);
  68.                                 IF ok THEN
  69.                                         BEGIN { The expression was parsed correctly }
  70.                                         NumberToHex  (value, str);
  71.                                         dcmdDrawLine (str);
  72.                                         END
  73.                                 ELSE
  74.                                   BEGIN { The expression contained an error. Get it as a string }
  75.                                         dcmdSetPosition (pos);
  76.                                   ch := dcmdGetNextParameter (str);
  77.                                   dcmdDrawLine (str);
  78.                                         END;
  79.                                 END;
  80.                 UNTIL ch = CHR(CR);
  81.                 END
  82.         ELSE
  83.   IF paramPtr^.request = dcmdHelp THEN
  84.           BEGIN { Display the command's help information }
  85.                 dcmdDrawLine ('ECHO [params...]');
  86.                 dcmdDrawLine ('   Echo the command line parameters');
  87.                 END;
  88. END;
  89.  
  90. END.
  91.